﻿using InTheHand.Net;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace MyTRCP.Client
{
    /// <summary>
    /// EditMacAddrWindow.xaml 的交互逻辑
    /// </summary>
    public partial class EditMacAddrWindow : Window
    {
        private readonly string _oldValue;
        private BluetoothAddress _newAddr;
        public BluetoothAddress NewAddr { get { return _newAddr; } }
        public EditMacAddrWindow(BluetoothAddress addr)
        {
            InitializeComponent();
            _oldValue = addr.ToString("C");
            _newAddr = (BluetoothAddress)addr.Clone();
            tb_old.Text = _oldValue;
            tb_new.Text = _oldValue;
        }
        public EditMacAddrWindow()
        {
            InitializeComponent();
            rd_old.Height = new GridLength(0);
            Height -= 35;
            _oldValue = string.Empty;
            _newAddr = new BluetoothAddress(0ul);
            tb_new.Text = _newAddr.ToString("C");
        }

        private void b_ok_Click(object sender, RoutedEventArgs e)
        {
            if (BluetoothAddress.TryParse(tb_new.Text, out BluetoothAddress result))
            {
                _newAddr = result;
                DialogResult = true;
                Close();
            }
            else
            {
                MessageBox.Show("MAC地址无法解析，请确认输入是否正确");
            }
        }

        private void b_cancel_Click(object sender, RoutedEventArgs e)
        {
            DialogResult = false;
            Close();
        }
    }
}
